//
//  CellForSideBarViewController.m
//  ppkc2016
//
//  Created by 拼凑的断音 on 16/3/7.
//  Copyright © 2016年 拼凑的断音. All rights reserved.
//

#import "CellForSideBarViewController.h"
#import "XXTool.h"

@implementation SideBarCellModel

@end

@interface CellForSideBarViewController ()

@property (nonatomic) UIImageView *leftImg;

@property (nonatomic) UILabel *rightLabel;

@property (nonatomic) UIView *line;

@property (nonatomic) UIView *messagePoint;

@property (nonatomic) UILabel *messageCountLabel;

@end

@implementation CellForSideBarViewController
-(UIImageView*)leftImg
{
    if (_leftImg==nil)
    {
        _leftImg = [[UIImageView alloc] init];
        _leftImg.contentMode = UIViewContentModeScaleAspectFill;
        [self addSubview:_leftImg];
    }
    return _leftImg;
}

-(UILabel*)rightLabel
{
    if (_rightLabel==nil)
    {
        _rightLabel = [[UILabel alloc] init];
        _rightLabel.font = [XXTool systemFontOfSize:14];
        _rightLabel.textColor = [UIColor whiteColor];
        [self addSubview:_rightLabel];
    }
    return _rightLabel;
}

-(UIView*)line
{
    if (_line==nil)
    {
        _line = [[UIView alloc] init];
        _line.backgroundColor = [UIColor colorWithRed:62/255.0 green:62/255.0 blue:62/255.0 alpha:1.0];
        [self addSubview:_line];
    }
    return _line;
}

-(UIView*)messagePoint
{
    if (_messagePoint==nil)
    {
        _messagePoint = [[UIView alloc] init];
        _messagePoint.backgroundColor = [UIColor colorWithRed:192/255.0 green:7/255.0 blue:18/255.0 alpha:1.0];
        _messagePoint.clipsToBounds = YES;
        [self addSubview:_messagePoint];
        
        _messageCountLabel = [[UILabel alloc] init];
        
        _messageCountLabel.backgroundColor = [UIColor clearColor];
        _messageCountLabel.textColor = [UIColor whiteColor];
        _messageCountLabel.font = [XXTool systemFontOfSize:8];
        _messageCountLabel.textAlignment = NSTextAlignmentCenter;
        [_messagePoint addSubview:_messageCountLabel];
    }
    return _messagePoint;
}

-(void)initParameter
{
    
}

-(void)initUI
{
    self.backgroundColor = [UIColor clearColor];
    [self leftImg];
    [self rightLabel];
    [self line];
}

-(void)refreshLayout:(CGRect)frame
{
    _leftImg.frame = CGRectMake(25
                                , 15
                                , 20
                                , 20);
    _rightLabel.frame = CGRectMake(_leftImg.frame.size.width+_leftImg.frame.origin.x+20
                                   , 0.4
                                   , frame.size.width-_leftImg.frame.origin.x*2-_leftImg.frame.size.width-20
                                   , 50);
    _line.frame = CGRectMake(_leftImg.frame.origin.x
                             , 49.6
                             , frame.size.width-25*2-50
                             , 0.4);
    if (!_messagePoint.hidden)
    {
        _messagePoint.frame = CGRectMake(_leftImg.frame.origin.x+_leftImg.frame.size.width-8
                                         , _leftImg.frame.origin.y-6
                                         , 10.5
                                         , 10.5);
        _messagePoint.layer.cornerRadius = _messagePoint.frame.size.width/2;
        
        _messageCountLabel.frame = CGRectMake(0, 0, _messagePoint.frame.size.width, _messagePoint.frame.size.height);
    }
}

-(void)setInfo:(NSMutableDictionary *)info
{
    SideBarCellModel *use = [info objectForKey:CellForSideBarViewControllerKey];
    _leftImg.image = [UIImage imageNamed:use.imgName];
    _rightLabel.text = use.labelName;
    _line.hidden = use.isHiddenLine;
    if (!use.messageVaild)
    {
        self.messagePoint.hidden = NO;
    }
    else
    {
        self.messagePoint.hidden = YES;
    }
    if (![use.messageCount isEqualToString:@""])
    {
        _messageCountLabel.hidden = NO;
        _messageCountLabel.text = use.messageCount;
    }
    else
    {
        _messageCountLabel.hidden = YES;
    }
    [self refreshLayout:self.frame];
}

@end
